﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;

namespace DSPrintSeting
{
    /// <summary>
    /// 得实打印机
    /// </summary>
    public static class InternalDASCOM_Printer_MethodDLL
    {
        /// <summary>
        /// 打开打印机
        /// </summary>
        /// <param name="portName"></param>
        /// <returns></returns>
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
        public static extern int OpenDevice(string portName);

        /// <summary>
        /// 关闭系统
        /// </summary>
        /// <returns></returns>
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int CloseDevice();

        /// <summary>
        /// 获取设备状态
        /// </summary>
        /// <returns></returns>
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int GetDeviceStatus();

        /// <summary>
        /// 获取打印机名称
        /// </summary>
        /// <returns></returns>
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int getPrinterName();
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern string sendPrName();

        /// <summary>
        /// 打印
        /// </summary>
        /// <param name="data"></param>
        /// <param name="mod"></param>
        /// <returns></returns>
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int PrintData(string data, ushort mod);
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern string GetUSBInfo();
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int SetPageOff(float Val);
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int PageOffVal();
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int SendCmdPageOff();

        /// <summary>
        /// 切纸
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int CutPaper(byte mode);
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int ChangePageCut(byte Options);

        /// <summary>
        /// 设置打印纸张页长（将忽略真实纸张高度）
        /// </summary>
        /// <param name="PageLen"></param>
        /// <returns></returns>
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int SetPageLength(float PageLen);
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int RestartDevice();
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int getPageOffVal(ref float high, ref float low);
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int getChangePageVal(ref byte cpVal);
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int getPageLenVal(ref float lenVal);
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int PageLenCmd(byte Options);
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int setUSBPortMark(string key);
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int getUSBPortMark(string port, StringBuilder key);
        [DllImport("DASCOM_Printer_MethodDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int getRunPageNum(ushort mode, ref int holesNum);

        /// <summary>
        /// 打印机正常
        /// </summary>
        public readonly static int DS_NORMAL = 116000;

        /// <summary>
        /// 设备忙+有纸
        /// </summary>
        public readonly static int DS_BUSY_WITHPAPER = 116001;

        /// <summary>
        /// 打印机忙（走纸、退纸、打印）
        /// </summary>
        public readonly static int DS_BUSY = 116002;

        /// <summary>
        /// 设备忙+缺纸
        /// </summary>
        public readonly static int DS_BUSY_WITHOUTPAPER = 116003;

        /// <summary>
        /// 设备忙+脱机
        /// </summary>
        public readonly static int DS_BUSY_OFFLINE = 116004;

        /// <summary>
        /// 设备忙+纸将尽
        /// </summary>
        public readonly static int DS_BUSY_PAPERLESS = 116005;


        /// <summary>
        /// 纸将尽+联机
        /// </summary>
        public readonly static int DS_NORMAL_PAPERLESS = 316001;

        /// <summary>
        /// 脱机，纸尽，缺纸
        /// </summary>
        public readonly static int DS_OFFLINE_PAPEROUT = 316002;

        /// <summary>
        /// 脱机
        /// </summary>
        public readonly static int DS_OFFLINE = 316003;

        /// <summary>
        /// 纸将尽+脱机
        /// </summary>
        public readonly static int DS_OFFLINE_PAPERLESS = 316005;

        /// <summary>
        /// 脱机，机械故障
        /// </summary>
        public readonly static int DS_MechanicalError = 416002;

        /// <summary>
        /// 端口打开失败
        /// </summary>
        public readonly static int DS_OpenPortFail = 416007;

        /// <summary>
        /// 无响应（设备未连接，通讯超时，设备故障）
        /// </summary>
        public readonly static int DS_NoResponding = 416008;

        /// <summary>
        /// 切刀出错
        /// </summary>
        public readonly static int DS_ErrorInCutPaper = 416010;

        /// <summary>
        /// 纸道出错
        /// </summary>
        public readonly static int DS_ErrorInPaperRoad = 416011;

        /// <summary>
        /// 卡纸出错
        /// </summary>
        public readonly static int DS_PaperStuck = 416012;

        /// <summary>
        /// 归位出错
        /// </summary>
        public readonly static int DS_ErrorInReset = 416013;

        /// <summary>
        /// 出错
        /// </summary>
        public readonly static int DS_Error = 616003;

        /// <summary>
        /// 出错，缺纸，脱机
        /// </summary>
        public readonly static int DS_ErrorPaperOut = 616004;

        public readonly static int DS_OK = 0;//成功

    }
}
